package com.hs.srm.base.datasources;

import com.baomidou.mybatisplus.mapper.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;

import java.util.Date;

/**
 * @program: HSSRM
 * @description:
 * @author: Wang Pei Dong
 * @create: 2018-08-06 16:05
 **/
public class CustomMetaObjectHandler extends MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        try {
            Object createTime = metaObject.getValue("createTime");
            Object lastModifyTime = metaObject.getValue("lastModifyTime");
            Date curr = new Date();
            if (null == createTime) {
                metaObject.setValue("createTime", curr);
            }
            if (null == lastModifyTime) {
                metaObject.setValue("lastModifyTime", curr);
            }
        } catch (Exception e) {
        }
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        insertFill(metaObject);
    }
}
